/*
 * Copyright (c) 2020 Carnegie Lee
 * All rights reserved
 */
package com.geekc.kafka.consumer;

import com.geekc.kafka.constant.KafkaConst;
import com.geekc.kafka.domain.Message;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.TopicPartition;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * 消费者 - 非Replying模式
 * @author Carnegie Lee
 */
//@Component
public class SimpleConsumer {

    @KafkaListener(id = KafkaConst.KAFKA_CONSUMER_GROUP_SIMPLE, topicPartitions = {
            @TopicPartition(topic = KafkaConst.KAFKA_TARGET_TOPIC_SIMPLE, partitions = {"0"})
    }, concurrency = KafkaConst.KAFKA_CONSUMER_CONCURRENCY, errorHandler = KafkaConst.KAFKA_CONSUMER_ERROR_HANDLER)
    public void receiveMessage(Message message, Acknowledgment ack) {
        System.out.println("接收到消息[id:" + message.getMessageId() + ",body:" + message.getMessageBody() + "]");
        //TODO
        //消息手动签收
        ack.acknowledge();
    }
}
